{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Graph adjacency list:\n",
      "A: B (weight 4), C (weight 2), D (weight 5)\n",
      "B: A (weight 4), C (weight 1), E (weight 1)\n",
      "C: A (weight 2), B (weight 1), D (weight 3)\n",
      "D: A (weight 5), C (weight 3), E (weight 2)\n",
      "E: B (weight 1), D (weight 2)\n"
     ]
    }
   ],
   "source": [
    "# 定义图的邻接表\n",
    "graph = {\n",
    "    'A': [('B', 4), ('C', 2), ('D', 5)],\n",
    "    'B': [('A', 4), ('C', 1), ('E', 1)],\n",
    "    'C': [('A', 2), ('B', 1), ('D', 3)],\n",
    "    'D': [('A', 5), ('C', 3), ('E', 2)],\n",
    "    'E': [('B', 1), ('D', 2)]\n",
    "}\n",
    "\n",
    "# 打印邻接表\n",
    "def print_adj_list(graph):\n",
    "    for node, edges in graph.items():\n",
    "        edge_list = ', '.join(f'{neighbor} (weight {weight})' for neighbor, weight in edges)\n",
    "        print(f'{node}: {edge_list}')\n",
    "\n",
    "# 打印图的结构\n",
    "print(\"Graph adjacency list:\")\n",
    "print_adj_list(graph)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
